package com.ruoyi.web.invest.stockApply.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.invest.stockApply.domain.StockApply;
import com.ruoyi.web.invest.stockApply.service.IStockApplyService;
import com.ruoyi.web.operate.stock.domain.Stock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 股票申购委托Controller
 *
 * @author feng_zi_xiang
 * @date 2021-08-26
 */
@RestController
@RequestMapping("/invest/stockApply")
public class StockApplyController extends BaseController
{
    @Autowired
    private IStockApplyService stockApplyService;

    /**
     * 查询股票申购委托列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockApply stockApply)
    {
        startPage();
        List<StockApply> list = stockApplyService.selectStockApplyList(stockApply);
        return getDataTable(list);
    }

    /**
     * 获取股票申购委托详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(stockApplyService.selectStockApplyById(id));
    }

    /**
     * 根据发行人id查询对应投资人
     *
     * @return 申购委托集合
     */
    @GetMapping("/selectDividendStockList")
    public TableDataInfo selectDividendStockList() {
        startPage();
        List<StockApply> list = stockApplyService.selectDividendStockList();
        return getDataTable(list);
    }

    /**
     * 新增股票申购委托
     */
    @Log(title = "股票申购委托", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockApply stockApply)
    {
        return toAjax(stockApplyService.insertStockApply(stockApply));
    }

    /**
     * 修改股票申购委托
     */
    @Log(title = "股票申购委托", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockApply stockApply)
    {
        return toAjax(stockApplyService.updateStockApply(stockApply));
    }

    /**
     * 删除股票申购委托
     */
    @Log(title = "股票申购委托", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(stockApplyService.deleteStockApplyByIds(ids));
    }

    /**
     * 确认申购委托单
     */
    @GetMapping(value = "/confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id) {
        return AjaxResult.success(stockApplyService.confirmStockApplyById(id));
    }


}
